home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Typography Samples / Dave’s Fab Samples ƒ / Kerning Adjustments.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  2.5 KB  |  89 lines  |  [TEXT/KAHL]

  1. #include <Types.h>
  2. #include <QuickDraw.h>
  3. #include <Fonts.h>
  4. #include <Windows.h>
  5. #include <Menus.h>
  6. #include <SegLoad.h>
  7. #include <Memory.h>
  8. #include <Desk.h>
  9.  
  10. #include "graphics routines.h"
  11. #include "graphics libraries.h"
  12. #include "graphics toolbox.h"
  13.  
  14. #include "layout types.h"
  15. #include "layout routines.h"
  16. #include "layout library.h"
  17.  
  18. #include "SampleInterface.h"
  19.  
  20. short MyStrLen(char *x);
  21. static short MyStrLen(x)
  22. char    *x;
  23.     {
  24.     short c = 0;
  25.     while (*x++) c++;
  26.     return c;
  27.     }    /* MyStrLen */
  28.  
  29. void KerningAdjustments(WindowPtr sampleWindow)
  30.     {
  31.     /* Variables */
  32.     char                *myString = "WAVE AWAY.";
  33.     gxGlyphcode            glyphcodes[20];
  34.     gxKerningAdjustment    gxKerningAdjustment;
  35.     gxLayoutOffsetState    offsetState;
  36.     gxPoint                myPoint;
  37.     gxRunControls            gxRunControls;
  38.     gxShape                layout;
  39.     short                len, level = 0;
  40.     gxStyle                myStyle;
  41.     unsigned short        firstGlyph, secondGlyph;
  42.     gxViewPort            aViewPort;
  43.     
  44.     /* Initialization */
  45.     
  46.     myPoint.x = ff(30);
  47.     myPoint.y = ff(50);
  48.     
  49.     aViewPort = GXNewWindowViewPort(sampleWindow);
  50.     SetDefaultViewPort(aViewPort);
  51.     
  52.     len = MyStrLen(myString);
  53.     InitializeRunControls(&gxRunControls);
  54.     
  55.     myStyle = NewLayoutStyle((char *) "\pHoefler Text", ff(60), 0, nil, nil, 0, nil);
  56.     
  57.     layout = GXNewLayout(
  58.         1, &len, (void *) &myString,
  59.         1, &len, &myStyle,
  60.         1, &len, &level,
  61.         nil, &myPoint);
  62.     GXDrawShape(layout);
  63.     
  64.     GXGetLayoutGlyphs(layout, glyphcodes, nil, nil, nil, nil, nil, nil);
  65.     GXGetOffsetGlyphs(layout, 1, false, &offsetState, &firstGlyph, &secondGlyph);
  66.     /* The "-1"s in the following lines convert from the 1-based space returned by GXGetOffsetGlyphs
  67.             into the zero-based space needed for array references. */
  68.     gxKerningAdjustment.firstGlyph = glyphcodes[firstGlyph - 1];
  69.     gxKerningAdjustment.secondGlyph = glyphcodes[secondGlyph - 1];
  70.     gxKerningAdjustment.crossStreamFactors.scaleFactor = 0;
  71.     gxKerningAdjustment.crossStreamFactors.adjustmentPointSizeFactor = 0;
  72.     
  73.     gxKerningAdjustment.withStreamFactors.scaleFactor = -(fract1 / 2);
  74.     gxKerningAdjustment.withStreamFactors.adjustmentPointSizeFactor = 0;
  75.     GXSetStyleRunKerningAdjustments(myStyle, 1, &gxKerningAdjustment);
  76.     GXMoveShape(layout, 0, ff(75));
  77.     GXDrawShape(layout);
  78.     
  79.     gxKerningAdjustment.withStreamFactors.scaleFactor = -fract1;
  80.     gxKerningAdjustment.withStreamFactors.adjustmentPointSizeFactor = fixed1 / 2;
  81.     GXSetStyleRunKerningAdjustments(myStyle, 1, &gxKerningAdjustment);
  82.     GXMoveShape(layout, 0, ff(75));
  83.     GXDrawShape(layout);
  84.     
  85.     GXDisposeShape(layout);
  86.     GXDisposeStyle(myStyle);
  87.     GXDisposeViewPort(aViewPort);
  88.     }    /* main */
  89.